package com.example.user3.demo.utils;

import android.content.Context;
import android.view.Gravity;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;


/**
 * 带颜色渐变和缩放的指示器标题
 * 博客: http://hackware.lucode.net
 * Created by hackware on 2016/6/26.
 */
public class ScaleTransitionPagerTitleView extends ColorTransitionPagerTitleView {
    private float mMinScale = 0.5f;
    private float mMinTranslation=5f;
    private float mMaxTextSize=18f;
    private boolean isSelectBig=true;
    private int gracityType=0;
    private int defTextSize=14;



    public ScaleTransitionPagerTitleView(Context context) {
        super(context);
    }

    @Override
    public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {
        super.onEnter(index, totalCount, enterPercent, leftToRight);    // 实现颜色渐变
//        setScaleX(mMinScale + (1.0f - mMinScale) * enterPercent);
//        setScaleY(mMinScale + (1.0f - mMinScale) * enterPercent);
//
//        setTranslationY(20f+(mMinTranslation-20f)*enterPercent);
        if (isSelectBig) {
            if (gracityType==0) {
                setGravity(Gravity.CENTER);
            }else if (gracityType==1){
                setGravity(Gravity.BOTTOM);
            }else {
                setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
            }
            setTextSize(defTextSize + (mMaxTextSize - defTextSize) * enterPercent);
        }else {
            if (gracityType==0) {
                setGravity(Gravity.CENTER);
            }else if (gracityType==1){
                setGravity(Gravity.BOTTOM);
            }else {
                setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
            }
        }
    }

    @Override
    public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {
        super.onLeave(index, totalCount, leavePercent, leftToRight);    // 实现颜色渐变
//        setScaleX(1.0f + (mMinScale - 1.0f) * leavePercent);
//        setScaleY(1.0f + (mMinScale - 1.0f) * leavePercent);
        if (isSelectBig) {
            if (gracityType==0) {
                setGravity(Gravity.CENTER);
            }else if (gracityType==1){
                setGravity(Gravity.BOTTOM);
            }else {
                setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
            }
            setTextSize(mMaxTextSize - (mMaxTextSize-defTextSize)*leavePercent);
        }else {
            if (gracityType==0) {
                setGravity(Gravity.CENTER);
            }else if (gracityType==1){
                setGravity(Gravity.BOTTOM);
            }else {
                setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
            }
        }


//        setTranslationY(mMinTranslation+(20.f-mMinTranslation)*leavePercent);
    }

    public int getGracityType() {
        return gracityType;
    }

    public void setGracityType(int gracityType) {
        this.gracityType = gracityType;
    }

    public boolean isSelectBig() {
        return isSelectBig;
    }

    public void setSelectBig(boolean selectBig) {
        isSelectBig = selectBig;
    }

    public float getMinScale() {
        return mMinScale;
    }

    public void setMinScale(float minScale) {
        mMinScale = minScale;
    }

    public float getmMaxTextSize() {
        return mMaxTextSize;
    }

    public void setmMaxTextSize(float mMaxTextSize) {
        this.mMaxTextSize = mMaxTextSize;
    }

    public int getDefTextSize() {
        return defTextSize;
    }

    public void setDefTextSize(int defTextSize) {
        this.defTextSize = defTextSize;
    }
}
